; TestController must be restarted before any changes in this file will be used.

; Manual is here: https://lygte-info.dk/project/TestControllerConfigDevice%20UK.html


; UNTESTED
#metadef
#idString HEWLETT-PACKARD,6631B,
#name HP 6631B
#handle HP6631B
#replaceText LowCurrent 0.002
#replaceText MaxCurrent 10.237
#replaceText MaxVoltage 8.190
#replaceText MaxProtectionVoltage 12 

#metadef
#idString HEWLETT-PACKARD,6632B,
#name HP 6632B
#handle HP6632B
#replaceText LowCurrent 0.002
#replaceText MaxCurrent 5.1188
#replaceText MaxVoltage 20.475
#replaceText MaxProtectionVoltage 22

#metadef
#idString HEWLETT-PACKARD,66332A,
#name HP 66332A
#handle HP66332A
#replaceText LowCurrent 0.002
#replaceText MaxCurrent 5.1188
#replaceText MaxVoltage 20.475
#replaceText MaxProtectionVoltage 22

; UNTESTED
#metadef
#idString HEWLETT-PACKARD,6633B,
#name HP 6633B
#handle HP6633B
#replaceText LowCurrent 0.002
#replaceText MaxCurrent 2.0475
#replaceText MaxVoltage 51.188
#replaceText MaxProtectionVoltage 55

; UNTESTED
#metadef
#idString HEWLETT-PACKARD,6634B,
#name HP 6634B
#handle HP6634B
#replaceText LowCurrent 0.002
#replaceText MaxCurrent 1.0238
#replaceText MaxVoltage 102.38
#replaceText MaxProtectionVoltage 110

#meta
#author WS
#idString HEWLETT-PACKARD,663xB,
#name HP 663xB
#handle HP663xB

#port comfixedbaud GPIB
#baudrate 9600N82
#driver SCPIx

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6) 
; Format: #value ColumnName Unit Format {Selector}
; Selector is only used when column layout varies with mode, this often require the use of #cmdMode
;  >>>>>>>>>>>>>>>>>>>>>>>
; Per HJK: When using columns to show on/off value, try declaring the datatype "digital(on)" instead of "D0"
;  >>>>>>>>>>>>>>>>>>>>>>>

; How to poll for data, this is used for table and #values?
; a #askMode, #cmdMode and #prepareSample is used before this is string is used.
; This is a single line command
#askValues MEAS:VOLT?;MEAS:CURR?

; A list of possible column name with unit and formatter (SI, Time, Int, D0..D6)
#value Voltage V D3 
#value Current A D4 

;Accept this delay when reading values (seconds)
#readingDelay 5

#scpiCmd init none
:setvar: varOpt760=0;

#scpiCmd initRS232 #pgm#
; filter out RS232 only command
if (portType!="GPIB")
  deviceWrite(handle,"SYST:REM");
endif;

#scpiCmd finalRS232 #pgm#
; filter out RS232 only command
if (portType!="GPIB")
  deviceWrite(handle,"SYST:LOC");
endif;

#scpiCmd Opt760 none (value)
:setvar: varOpt760=inputValue;

#scpiCmd Opt760? none?
:readmath: varOpt760;

; Initial commands to meter when establishing connection
#initCmd *CLS;*RST;init;initRS232;

; Final command to meter before breaking connection
#finalCmd OUTP 0;finalRS232

; Used when output off button is pressed
#outputOff OUTP 0

#interfaceType PS
#interface setVoltage VOLT:LEVEL:IMM (value)
#interface setCurrent CURR:LEVEL:IMM (value)
#interface setOn OUTP (value)
#interface getVoltage VOLT:LEVEL:IMM?
#interface getCurrent CURR:LEVEL:IMM?
#interface getOn OUTP?
#interface readVoltage 0
#interface readCurrent 1

; Strings to configure device in different modes
; First parameter must match a #value (4 parameter) and second parameter must match what #askMode returns
; First parameter is also used in shortcut menu
;#cmdMode 

; Setup menu functions
; The parameters on the first line is: type name page 
; Settings on the following lines are:
; read: SCPI to read value from device, is used to synchronize when opening setup page or setting equal named fields. Not always used
; readformat: Parse read value.
; write: Send the value to device, this field is used in combination with data fields in the details to send updates to device.
; tip: Add this tip to all components for this input field.

#cmdSetup buttonsOn Output
:write: OUTP #
:read: OUTP?
:updatedelayed: 0.2
:update: Output_Relay Output_Polarity_Reversed
Off 0
On 1

#cmdSetup number Voltage Main
:read: VOLT:LEV:IMM?
:write: VOLT:LEV:IMM
:updatedelayed: 0.1
V 0 MaxVoltage

#cmdSetup number Current Main
:read: CURR:LEV:IMM?
:write: CURR:LEV:IMM
:updatedelayed: 0.1
A 0 MaxCurrent

#cmdSetup number Current_Range Main
:write: SENS:CURR:RANG
:read: SENS:CURR:RANG?
:tip: Set Maximal Measuring Range, variable
:updatedelayed: 0.1
A 0 MaxCurrent

#cmdSetup buttonsOn Current_Range_Easy Main
:write: SENS:CURR:RANG
:tip: Set Maximal Measuring Range, the easy way
:updatedelayed: 0.1
:update: Current_Range
Low LowCurrent
High MaxCurrent


#cmdSetup checkbox Relay_Board Main
; This is used for activating the relay board option #760.
; - Unfortunately *OPT? only returns "0" (on FW 1.03), so this must be controlled manually
:read: Opt760?
:write: Opt760
:update: No_Relay_Board
:tip: Output Relay Board (#760) present?
Installed 0 1

#cmdSetup selector No_Relay_Board Main
:read: Opt760?
;displayVar(split(getVarList(1),"[\\n]"));
; The name is weird because the name of this selector shows up only when disabled.
0
1 Main.Output_Relay;Main.Output_Polarity_Reversed

#cmdSetup checkbox Output_Relay Main
:read: OUTP:REL?
:write: OUTP:REL
:tip: Output relay control
:updatealloff:
:updatedelayed: 0.1
On 0 1

#cmdSetup checkbox Output_Polarity_Reversed Main
:read: OUTP:REL:POL?
:write: OUTP:REL:POL
:string:
:tip: Output relay polarity control
:updatealloff:
:updatedelayed: 0.1
Reversed NORM REV

#cmdSetup number OVP_Voltage Limits
:read: VOLT:PROT:LEV?
:write: VOLT:PROT:LEV
:tip: OVP can't be disabled, so set it to maximum value if not needed.
:updatedelayed: 0.1
V 0 MaxProtectionVoltage

#cmdSetup buttonsOn OCP Limits
:read: CURR:PROT:STAT?
:write: CURR:PROT:STAT
:tip: OCP ist tripped when powersupply switches from CV to CC mode.
:updatedelayed: 0.1
Off 0
On 1

#cmdSetup number OCP_delay Limits
:read: OUTP:PROT:DEL?
:write: OUTP:PROT:DEL
:tip: Disables OCP for the configured time after programming an output change.
s 0 2147483.647

#cmdSetup button OCP_OVP_Clear Limits
:write: OUTP 0;OUTP:PROT:CLE

#cmdSetup button Save_0 Store
:write: *SAV 0

#cmdSetup button Save_1 Store
:write: *SAV 1
 
#cmdSetup button Save_2 Store
:write: *SAV 2

#cmdSetup button Save_3 Store
:write: *SAV 3

#cmdSetup button Restore_0 Store
:write: *RCL 0
:update: buttonsOn;Voltage;Current;Current_Range;OVP_Voltage;OCP;OCP_delay

#cmdSetup button Restore_1 Store
:write: *RCL 1
:update: buttonsOn;Voltage;Current;Current_Range;OVP_Voltage;OCP;OCP_delay

#cmdSetup button Restore_2 Store
:write: *RCL 2
:update: buttonsOn;Voltage;Current;Current_Range;OVP_Voltage;OCP;OCP_delay

#cmdSetup button Restore_3 Store
:write: *RCL 3
:update: buttonsOn;Voltage;Current;Current_Range;OVP_Voltage;OCP;OCP_delay

